package xyz.scootaloo.draft;

import java.util.LinkedList;
import java.util.ListIterator;

/**
 * @author flutterdash@qq.com
 * @since 2021/3/29 22:13
 */
public class Case4 {

    public static void main(String[] args) {
        LinkedList<Person> persons = initAndGet();
        System.out.println(persons);
        ListIterator<Person> iterator = persons.listIterator();
        while (iterator.hasNext()) {
            Person currentPerson = iterator.next();
            if (currentPerson.name.equals("李四")) {
                iterator.add(new Person("赵六",133,"nan","北京"));
            } else if (currentPerson.name.equals("王五")) {
                iterator.remove();
            }
        }
        System.out.println(persons);
    }

    /**
     *
     * [1,  2,  3,  4,  5]
     */
    private static LinkedList<Person> initAndGet() {
        LinkedList<Person> persons = new LinkedList<>();
        persons.add(new Person("张三",23,"男","河南"));
        persons.add(new Person("李四",23,"男","河南"));
        persons.add(new Person("张三",23,"男","河南"));
        persons.add(new Person("王五",23,"男","河南"));
        persons.add(new Person("张三",23,"男","河南"));
        return persons;
    }

    private static class Person {
        String name;
        Integer age;
        String sex;
        String region;
        public Person(String name, Integer age, String sex, String region) {
            this.name = name;
            this.age = age;
            this.sex = sex;
            this.region = region;
        }

        @Override
        public String toString() {
            return "\nPerson{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    ", sex='" + sex + '\'' +
                    ", region='" + region + '\'' +
                    '}';
        }
    }

}
